package ElasticProvider

import (
	"Volta/Config"
	"context"
	"fmt"
	"github.com/olivere/elastic/v7"
)

type ElasticSearch struct {
	Conn *elastic.Client
}

func (pr *ElasticSearch) Connect() bool{
	fmt.Println(Config.Server.ESHost)
	client, err := elastic.NewClient(elastic.SetSniff(false),elastic.SetURL(Config.Server.ESHost))
	if err != nil {
		fmt.Println(err.Error())
		return false
	}
	_, code, err := client.Ping(Config.Server.ESHost).Do(context.Background())
	if err != nil {
		fmt.Println("elastic ping err",code)
		return false
	}
	_, err = client.ElasticsearchVersion(Config.Server.ESHost)
	if err != nil {
		fmt.Println("elastic search version err")
		return false
	}
	pr.Conn = client
	return true
}

func (pr *ElasticSearch) GetElastic() *elastic.Client {
	return pr.Conn
}


